import {reqCatalogList,reqBannerList,reqFloorList} from '@/api'
const actions = {
    async addcataloglist(context) {
        const result = await reqCatalogList()
        if (result.code === 200) {
            context.commit('GET_CATALOG_LIST', result.data)
            console.log('请求成功');
        } else {
            console.log(result.message);
        }
    },
    async addbannerlist(context){
        // 这里的result也是一个promise对象，所以之前要写成Promise.reject(new Error(error.message))这样才能进来之后是失败状态。如果是字符串进来后，依然是成功状态。
        const result = await reqBannerList()
        if(result.code===200){
            context.commit('GET_BANNER_LIST',result.data)
        }else{
            return error.message
        }
    },
    async addfloorlist(context){
        const result = await reqFloorList()
        if(result.code === 200){
            context.commit('GET_FLOOR_LIST',result.data)
        }else{
            console.log('reqfloorlist失败',result.message)
        }
    }
}
const state = { 
    catalogList: [],
    bannerList:[],
    floorList:[],
}
const mutations = {
    GET_CATALOG_LIST(state, list) {
        state.catalogList = list
        console.log(state.catalogList)
    },
    GET_BANNER_LIST(state,list){
        state.bannerList=list
        console.log(state.bannerList);//Array[4]id/imgUrl
    },
    GET_FLOOR_LIST(state,list){
        state.floorList=list
        console.log('floorlist数据',state.floorlist)
    }
}
export default {
    namespaced:true,
    actions,
    state,
    mutations,}